def power(x,n=2):
	s = 1
	while n>0:
		n = n - 1
		s = s * x
	return s

print(power(5,4))
print(power(4))

def enroll(name,gender,age=10,city="wuxi"):
	print("name",name)
	print("gender",gender)
	print("age",age)
	print("city",city)

enroll("fesine","A")

def add_end(L=None):
	if L is None:
		L=[]
	L.append("END")
	return L

print(add_end())
print(add_end([1,2,3]))

def calc(*numbers):
	sum = 0;
	for n in numbers:
		sum = sum + n * n
	return sum

print(calc(1,2,3,4))
print(calc())
print(calc(*[1,3,5,6]))

# 关键字参数 可变参数允许你传入0个或任意个参数
def person(name,age,**kw):
	if "city" in kw:
		pass
	if "job" in kw:
		pass
	print("name:",name,"age:",age,"other:",kw)
person("fesine",30,city="wuxi",gender="M",cell="18850501212")

# 命名关键字参数
# 限制关键字参数的名字 只接收city和job作为关键字参数
def person2(name,age,*,city='shanghai',job='boss'):
	print("name:",name,"age:",age,"city:",city,"job",job)
# 命名关键字参数必须传入参数名，这和位置参数不同。如果没有传入参数名，调用将报错：
person2("soly",33,city="wuxi",job="it")
person2("soly",32)

# 参数组合
# 在Python中定义函数，可以用必选参数、默认参数、可变参数、关键字参数和命名关键字参数，
# 这5种参数都可以组合使用。但是请注意，参数定义的顺序必须是：
# 必选参数、默认参数、可变参数*、命名关键字参数和关键字参数**。
def f1(a, b, c=0, *args, **kw):
    print('a =', a, 'b =', b, 'c =', c, 'args =', args, 'kw =', kw)

def f2(a, b, c=0, *, d, **kw):
    print('a =', a, 'b =', b, 'c =', c, 'd =', d, 'kw =', kw)

f1(1,2)
f1(1,2,3)
f1(1,2,4,'a','b')
f1(1,2,4,'a','b',x=99)
f2(1,2,5,cell="188",d=99,ext=None)

args = (1, 2, 3, 4)
kw = {'d': 99, 'x': '#'}
f1(*args, **kw)
args = (1, 2, 3)
kw = {'d': 88, 'x': '#'}
f2(*args, **kw)




